Skip to content

Submit Design-2 PR - #2488

Open
agk-s30 wants to merge 2 commits into
super30admin:masterfrom
agk-s30:master
Open

Submit Design-2 PR#2488
agk-s30 wants to merge 2 commits into
super30admin:masterfrom
agk-s30:master

Conversation

@agk-s30

@agk-s30 agk-s30 commented Jul 30, 2026

Copy link
Copy Markdown

No description provided.

agk-s30 added 2 commits July 30, 2026 02:23
Implemented a MyHashMap class with methods for put, get, and remove operations using a linked list for collision handling.
Implemented a queue using two stacks, with methods for push, pop, peek, and checking if the queue is empty.
@super30admin

Copy link
Copy Markdown
Owner

Implement Queue using Stacks (Exercise_1.py)

Strengths:

  • Your solution correctly implements the queue using two stacks with the standard approach
  • Good code structure and readability
  • Clear comments explaining the algorithm
  • Variable naming is descriptive

Areas for improvement:

  • The return -1 statements in pop() and peek() are unnecessary since the problem guarantees that all calls to these methods are valid. The reference solution doesn't include these checks. While they don't break correctness, they add unnecessary code.
  • In pop(), you call self.peek() which performs its own empty check, but you've already checked self.empty() in pop(). This is a minor redundancy.
  • Consider whether the time complexity comment "O(1)" is accurate - it should be "Amortized O(1)" since the transfer operation is O(n) in the worst case.

Overall, this is a solid solution that correctly solves the problem.

VERDICT: PASS


Design HashMap (Exercise_2.py)

Strengths:

  • The _get_prev helper method is an excellent design pattern that simplifies the implementation of all three operations.
  • The sentinel node approach (pre-populating each bucket with a default Node()) is a clean way to avoid edge cases.
  • Using 10000 buckets is a thoughtful choice given the constraint of at most 10^4 calls.
  • The code is well-documented with comments explaining the approach and complexity.
  • Type hints improve code readability and maintainability.

Minor Suggestions:

  • Consider adding a brief docstring to the MyHashMap class explaining the overall design.
  • The Node class could benefit from a __repr__ method for easier debugging.
  • You could add a small note about why 10000 buckets was chosen (to minimize collisions given the constraints).

Overall:
This is a high-quality solution that demonstrates strong understanding of hash map design, collision resolution via chaining, and clean code principles. The implementation is functionally equivalent to the reference solution with thoughtful optimizations.

VERDICT: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants